<?php
	class code{
	    private $arrCheck='0123456789abcdefghijklmnopqrstuvwxyz';
	    private $string='';
		private $width;
		private $height;
		public function __construct($width=90,$height=20){
			//session_start();
			$this->width=$width;
			$this->height=$height;
			for($i=1;$i<=4;$i++){
				$this->string.=$this->arrCheck[rand(0,35)];
				}
			$_SESSION['c_string']=$this->string;
		}
		public function showCode(){
				header("Content-Type:image/png");//指定图片的输出格式
				$img=imagecreate($this->width,$this->height);//创建图片的大小
				imagecolorallocate($img,255,255,255);//为图像分配颜色第一个为底板色
				for($i=0;$i<100;$i++){
					$color=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
					imagesetpixel($img,rand(0,90),rand(5,15),$color);
				}
				//$color=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
				imagestring($img,6,rand(20,40),rand(0,6),$this->string,$color);//图片填充字符串
				imagepng($img);
				imagedestroy($img);
				//header("Content-Type:text/html");
		}
	}
	$oImg=new code();
	$oImg->showCode();
?>